#!/usr/bin/env python
# coding=utf-8
import ansible.runner
import json
import os
#os.environ["ANSIBLE_HOSTS"]='/etc/ansible/ansible_hosts'
#os.environ["ANSIBLE_CONFIG"]='/etc/ansible/ansible.cfg'

def zabbix_restart(ip):
	runner = ansible.runner.Runner(
	module_name='shell',
	module_args='/usr/local/zabbix/bin/zabbix_get -s  %s  -k system.run["/usr/local/bin/restart.sh"]' %(ip),
	#pattern='172.16.30.42',
	host_list=["172.16.30.42"],
	extra_vars={"ansible_ssh_user":"root","ansible_ssh_pass":"palmc2013#$%"},
	forks=1
	)
	datastructure = runner.run()
	data = json.dumps(datastructure,indent=4)
	#print data
	#return data
	true='true'
	dd=eval(data)
	ddd=dd['contacted']['172.16.30.42']



	if not ddd['stderr'] and int(ddd['stdout']) == 1:
		return 1
	else:
		return 0
